package pers.xiaojun.boot.security.handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import static pers.xiaojun.boot.common.constants.GlobalBusinessCodeConstants.FORBIDDEN;
import pers.xiaojun.boot.common.pojo.CommonResult;
import pers.xiaojun.boot.web.core.util.ServletUtils;

import java.io.IOException;

/**
 * 无权限处理器
 *
 * @author xiaojun
 * @since 2025-10-04
 */
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ServletUtils.writeJSON(response, CommonResult.error(FORBIDDEN));
    }

}
